home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / dosrcss.zip / RCSFCMP.C < prev    next >
C/C++ Source or Header  |  1990-07-18  |  7KB  |  232 lines

  1. /*
  2.  *                     RCS file comparison
  3.  */
  4. #ifndef lint
  5. static char rcsid[]= "$Id: rcsfcmp.c,v 5.2 90/07/15 11:33:36 ROOT_DOS Release $ Purdue CS";
  6. #endif
  7. /*****************************************************************************
  8.  *                       rcsfcmp()
  9.  *                       Testprogram: define FCMPTEST
  10.  *****************************************************************************
  11.  */
  12.  
  13. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  14.    Distributed under license by the Free Software Foundation, Inc.
  15.  
  16. This file is part of RCS.
  17.  
  18. RCS is free software; you can redistribute it and/or modify
  19. it under the terms of the GNU General Public License as published by
  20. the Free Software Foundation; either version 1, or (at your option)
  21. any later version.
  22.  
  23. RCS is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26. GNU General Public License for more details.
  27.  
  28. You should have received a copy of the GNU General Public License
  29. along with RCS; see the file COPYING.  If not, write to
  30. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  31.  
  32. Report problems and direct all questions to:
  33.  
  34.     rcs-bugs@cs.purdue.edu
  35.  
  36. */
  37.  
  38.  
  39.  
  40.  
  41.  
  42. /* $Log:    rcsfcmp.c,v $
  43.  * Revision 5.2  90/07/15  11:33:36  ROOT_DOS
  44.  * DOS version of RCS 4.0 checked in for MODS
  45.  * by lfk@athena.mit.edu
  46.  * Also update to MSC 6.0
  47.  * 
  48.  * Revision 4.5  89/05/01  15:12:42  narten
  49.  * changed copyright header to reflect current distribution rules
  50.  * 
  51.  * Revision 4.4  88/11/08  12:01:33  narten
  52.  * changes from  eggert@sm.unisys.com (Paul Eggert)
  53.  * 
  54.  * Revision 4.4  88/08/09  19:12:50  eggert
  55.  * Shrink stdio code size.
  56.  * 
  57.  * Revision 4.3  87/12/18  11:40:02  narten
  58.  * lint cleanups (Guy Harris)
  59.  * 
  60.  * Revision 4.2  87/10/18  10:33:06  narten
  61.  * updting version number. Changes relative to 1.1 actually relative to 
  62.  * 4.1
  63.  * 
  64.  * Revision 1.2  87/03/27  14:22:19  jenkins
  65.  * Port to suns
  66.  * 
  67.  * Revision 1.1  84/01/23  14:50:23  kcs
  68.  * Initial revision
  69.  * 
  70.  * Revision 4.1  83/05/10  16:24:04  wft
  71.  * Marker matching now uses trymatch(). Marker pattern is now
  72.  * checked precisely.
  73.  * 
  74.  * Revision 3.1  82/12/04  13:21:40  wft
  75.  * Initial revision.
  76.  *
  77.  */
  78.  
  79. /*
  80. #define FCMPTEST
  81. /* Testprogram; prints out whether two files are identical,
  82.  * except for keywords
  83.  */
  84.  
  85. #include  "rcsbase.h"
  86. extern FILE * fopen();
  87. extern enum markers trymatch(); /* check for keywords */
  88.  
  89.  
  90. rcsfcmp(xfname,uxfname,delta)
  91. char * xfname, *uxfname; struct hshentry *delta;
  92. /* Function: compares the files xfname and uxfname. Returns true
  93.  * if xfname has the same contents as uxfname, while disregarding
  94.  * keyword values. For the LOG-keyword, rcsfcmp skips the log message
  95.  * given by the parameter delta in xfname. Thus, rcsfcmp returns true
  96.  * if xfname contains the same as uxfname, with the keywords expanded.
  97.  * Implementation: character-by-character comparison until $ is found.
  98.  * If a $ is found, read in the marker keywords; if they are real keywords
  99.  * and identical, read in keyword value. If value is terminated properly,
  100.  * disregard it and optionally skip log message; otherwise, compare value.
  101.  */
  102. {
  103.     register int xc,uxc;
  104.     char xkeyword[keylength+2],   uxkeyword[keylength+2];
  105.     char xkeyval[keyvallength+1], uxkeyval[keyvallength+1];
  106.     register FILE * xfp, * uxfp;
  107.     register char * tp;
  108.     int result;
  109.     enum markers match1,match2;
  110.  
  111.     if ((xfp=fopen(tp=xfname,"r"))==NULL || (uxfp=fopen(tp=uxfname,"r"))==NULL) {
  112.        faterror("Can't open %s\n", tp);
  113.        return false;
  114.     }
  115.     result=false;
  116.     xc=getc(xfp); uxc=getc(uxfp);
  117.     while( xc == uxc) { /* comparison loop */
  118.         if (xc==EOF) { /* finished; everything is the same*/
  119.             result=true;
  120.             break;
  121.         }
  122.         if ( xc!=KDELIM) {
  123.             /* get the next characters */
  124.             xc=getc(xfp); uxc=getc(uxfp);
  125.         } else {
  126.             /* try to get both keywords */
  127.             tp = xkeyword;
  128.             while( (xc=getc(xfp))!=EOF && (tp< xkeyword+keylength) && (xc!='\n')
  129.                    && (xc!=KDELIM) && (xc!=VDELIM))
  130.                 *tp++ = xc;
  131.         *tp++ = xc;  /* add closing K/VDELIM */
  132.             *tp='\0';
  133.             tp = uxkeyword;
  134.             while( (uxc=getc(uxfp))!=EOF && (tp< uxkeyword+keylength) && (uxc!='\n')
  135.                    && (uxc!=KDELIM) && (uxc!=VDELIM))
  136.                 *tp++ = uxc;
  137.         *tp++ = xc;  /* add closing K/VDELIM */
  138.             *tp='\0';
  139.             /* now we have 2 keywords, or something thal looks like it.*/
  140.         match1=trymatch(xkeyword,false);
  141.         match2=trymatch(uxkeyword,false);
  142.         if (match1 != match2) break; /* not identical */
  143. #ifdef FCMPTEST
  144.         VOID printf("found potential keywords %s and %s\n",xkeyword,uxkeyword);
  145. #endif
  146.  
  147.         if (match1 == Nomatch) {
  148.         /* not a keyword pattern, but could still be identical */
  149.         if (strcmp(xkeyword,uxkeyword)==0)
  150.              continue;
  151.         else break;
  152.         }
  153. #ifdef FCMPTEST
  154.         VOID printf("found common keyword %s\n",xkeyword);
  155. #endif
  156.         tp=xkeyval;
  157.         if (xc==VDELIM) {/* get value */
  158.         while (((xc=getc(xfp))!=KDELIM) && (xc!='\n') && (xc!=EOF) &&
  159.             (tp<xkeyval+keyvallength))
  160.             *tp++ = xc;
  161.         }
  162.         *tp = '\0';   /*xkeyval now filled with value; possibly empty*/
  163.         tp=uxkeyval;
  164.         if (uxc==VDELIM) {/* get value */
  165.         while (((uxc=getc(uxfp))!=KDELIM) && (uxc!='\n') && (uxc!=EOF) &&
  166.             (tp<uxkeyval+keyvallength))
  167.             *tp++ = uxc;
  168.         }
  169.         *tp = '\0';   /*uxkeyval now filled with value; possibly empty*/
  170.         if (xc!=uxc) break; /* not the same */
  171.         if (xc==KDELIM) {
  172.         xc=getc(xfp); uxc=getc(uxfp); /* skip closing KDELIM */
  173.         /* if the keyword is LOG, also skip the log message in xfp*/
  174.         if (match1==Log) {
  175.             /* first, compute the number of line feeds in log msg */
  176.             int lncnt, ccnt;
  177.             lncnt=2; tp=delta->log;
  178.             while(*tp) if(*tp++=='\n') lncnt++;
  179.             while(xc!=EOF) {
  180.             if (xc=='\n')
  181.                 if(--lncnt==0) break;
  182.             xc=getc(xfp);
  183.             }
  184.             /* skip last comment leader */
  185.             /* Can't just skip another line here, because there may be */
  186.             /* additional characters on the line (after the Log....$)  */
  187.             for (ccnt=strlen(Comment); ccnt>=0; lncnt--) {
  188.             xc=getc(xfp);
  189.             if(xc=='\n') break;
  190.             /* reads to the end of the comment leader or '\n',     */
  191.             /* whatever comes first. This is because some editors  */
  192.             /* strip off trailing blanks from a leader like " * ". */
  193.             }
  194.         }
  195.         } else {
  196.         /* both end in the same character, but not a KDELIM */
  197.         /* must compare string values.*/
  198. #ifdef FCMPTEST
  199.         VOID printf("non-terminated keywords %s, potentially different values\n",xkeyword);
  200. #endif
  201.         if (strcmp(xkeyval,uxkeyval)!=0) break; /*different */
  202.         xc=getc(xfp); uxc=getc(uxfp); /* skip closing char  */
  203.             }
  204.         }
  205.     }
  206.     VOID fclose(xfp); VOID fclose(uxfp);
  207.     return result;
  208. }
  209.  
  210.  
  211.  
  212. #ifdef FCMPTEST
  213. char * RCSfilename, * workfilename;
  214.  
  215. char * Comment;
  216.  
  217. main(argc, argv)
  218. int  argc; char  *argv[];
  219. /* first argument: comment leader; 2nd: log message, 3rd: expanded file,
  220.  * 4th: unexpanded file
  221.  */
  222. {       struct hshentry delta;
  223.  
  224.         cmdid="rcsfcmp";
  225.         Comment=argv[1];
  226.         delta.log=argv[2];
  227.         if (rcsfcmp(argv[3],argv[4],&delta))
  228.                 VOID printf("files are the same\n");
  229.         else    VOID printf("files are different\n");
  230. }
  231. #endif
  232.